<template>
<div class="padding10">
  <div v-if="!dialogVisible">
    <assessmentResult :personnel="personnel" :assessmentData="resultData" :notShare="true"></assessmentResult>
  </div>
  <el-dialog width="400px"
  :title="dialogTitle"
  :visible.sync="dialogVisible"
  :before-close="handleClose">
    <div class="verifyBox">
      <label>查看密码：</label> <span><input type="password" v-model="pw"/></span>
      <button v-on:click="getShareResult">查看</button>
    </div>
  </el-dialog>
  <!-- 弹出框 -->
  <el-dialog
    :title="alertTitle"
    :visible.sync="alertOpen"
    width="40%">
    <div v-html="alertBody"></div>
  </el-dialog>
</div>
</template>

<script>
import Vue from "vue";
import assessmentResult from './views/assessment/insAssessResult.vue'

export default {
  name: 'share',
  data () {
    return {
      dialogVisible: true,
      dialogTitle: '查看机构评估结果',
      reportId: -1,
      pw: '',
      resultData: {},
      personnel: {},
      alertOpen: false,
      alertTitle: "",
      alertBody: "",
    }
  },
  props: {
  },
  components: {
    assessmentResult
  },
  methods: {
    handleClose (done) {
      this.$confirm('确认关闭？').then(_ => { done() }).catch(_ => {})
    },
    getShareResult () {
      this.$http.post('share/share?reportId=' + this.reportId + '&pass=' + this.pw).then(
        response => {
          this.resultData = response.data.data.assessmentData
          let personnelData = response.data.data.personnelData
          personnelData.reportId = this.reportId
          personnelData.pw = this.pw
          this.personnel = personnelData
          this.dialogVisible = false
/*
          this.resultData = response.data.data
          this.$http.get('cutomer/getById?id=' + response.data.data.personnelId ).then(
            resp => {
              this.personnel = resp.data.data
              this.dialogVisible = false
            }
          )
*/
        }
      )
    },
    alert(body, title, open) {
      this.alertTitle = title
      this.alertBody = body
      this.alertOpen = open
    }
  },
  watch: {
    // 监听参数变化
    options: {
      handler: function(val) {
        this.options = val;
        this.renderCharts();
      },
      // 深度观察
      deep: true
    }
  },
  beforeCreate () {},
  created () {
    Vue.prototype.$alert = this.alert
    // console.log(location.href.match(/\?reportId=(\d*)&?/i))
    this.reportId = location.href.match(/\?reportId=(\d*)&?/i)[1]
  },
  beforeMount () {},
  mounted () {},
  beforeUpdate () {},
  updated () {},
  beforeDestroy () {},
  destroyed () {}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.verifyBox{min-width:360px; max-width:600px; margin:auto;}
</style>
